package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.mapper.SysDictDataMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {
    @Autowired
    private TbBusinessMapper tbBusinessMapper;
    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    @Autowired
    private SysDictDataMapper dictDataMapper;

    @Override
    @Transactional
    public void insertBusinessTrackRecord(TbBusinessTrackRecord tbBusinessTrackRecord,TbBusiness TbBusiness) {
        tbBusinessMapper.updateTbBusiness(TbBusiness);
        tbBusinessTrackRecordMapper.insertBusinessTrackRecord(tbBusinessTrackRecord);
    }

    @Override
    public List<TbBusinessTrackRecord> selectByIbBusinessTrackRecord(Long id) {
        List<TbBusinessTrackRecord> businessTrackRecord = tbBusinessTrackRecordMapper.selectByIbBusinessTrackRecord(id);
         List<TbBusinessTrackRecord> list=new ArrayList<>();
        for (int i = 0; i < businessTrackRecord.size(); i++) {
            TbBusinessTrackRecord tbBusinessTrackRecord= businessTrackRecord.get(i);
        String keyItems = tbBusinessTrackRecord.getKeyItems();
        String[] split = keyItems.split(",");
        List<String> strings=new ArrayList<>();
        for (String s : split) {
            String communicationPoint = dictDataMapper.selectDictLabel("communication_point", s);
            strings.add(communicationPoint);
        }
        tbBusinessTrackRecord.setKeys(strings);
        list.add(tbBusinessTrackRecord);
        }


//         list.add(tbBusinessTrackRecord);
//        BusinessTrackVo businessTrackVo = new BusinessTrackVo();
//        BeanUtils.copyProperties(businessTrackRecord,businessTrackVo);

        return list;
    }
}
